package cn.edu.scau.cmil.linwei.comprehensive.Controller;


import cn.edu.scau.cmil.linwei.comprehensive.util.StageManager;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.net.URL;
import java.util.ResourceBundle;

public class TipController implements Initializable {
    public BorderPane borderPane;
    public Text TipText;
    public Button ButtonLeft;
    public Button ButtonRight;

    //标题栏最小化、关闭、拖拽
    private double oldStageX,oldStageY,oldScreenX,oldScreenY;//点击时记录窗口的XY
    //最小化
    public void MinButtonClicked(){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setIconified(true);
    }//设置最小化按钮点击时发生的活动选项
    //关闭
    public void CloseButtonClicked(){
        TeacherMainWindowsController controller = (TeacherMainWindowsController)
                StageManager.CONTROLLERMAP.get("TeacherMainWindowsController");
        controller.setTipChoose(false);
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.close();
    }//设置关闭按钮点击时发生的活动选项
    //鼠标拖拽
    public void MousePressed(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        oldStageX = stage.getX();//事件相对于MouseEvent源的原点的水平位置，即获取当前鼠标位置
        oldStageY = stage.getY();//事件相对于MouseEvent源的原点的垂直位置，即获取当前鼠标位置
        oldScreenX = event.getScreenX();//返回事件的绝对水平位置，即获取窗口左上角位置
        oldScreenY = event.getScreenY();//返回事件的绝对垂直位置，即获取窗口左上角位置
    }

    public void MouseDragged(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setX(event.getScreenX()-oldScreenX+oldStageX);
        stage.setY(event.getScreenY()-oldScreenY+oldStageY);
    }



    public void CloseTipWindows(){
        Stage stage = (Stage)borderPane.getScene().getWindow();//通过布局获取场景再获取舞台
        stage.close();//关闭舞台
    }

    public void InitPane(){
        TeacherMainWindowsController controller = (TeacherMainWindowsController)
                StageManager.CONTROLLERMAP.get("TeacherMainWindowsController");
        TipText.setText(controller.getTipText());
        ButtonLeft.setText(controller.getButtonLeftText());
        ButtonRight.setText(controller.getButtonRightText());
    }//获取三个控件应该显示的信息

    public void ButtonLeftClicked(){
        TeacherMainWindowsController controller = (TeacherMainWindowsController)
                StageManager.CONTROLLERMAP.get("TeacherMainWindowsController");
        controller.setTipChoose(true);
        CloseTipWindows();
    }

    public void ButtonRightClicked(){
        TeacherMainWindowsController controller = (TeacherMainWindowsController)
                StageManager.CONTROLLERMAP.get("TeacherMainWindowsController");
        controller.setTipChoose(false);
        CloseTipWindows();
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        InitPane();
    }
}
